<?php

namespace app\admin\controller;

use support\Request;
use support\Response;
class MockController
{

    /**
     * 模拟数据
     * @param Request $request
     * @param $name
     * @return Response
     */
    public function index(Request $request, $name): Response
    {
        $path = public_path('/mock/' . $name . '.json');
        if (!is_file($path)) return success(message());
        $type = $request->input('type') ?? '';
        $quota = $request->input('quota') ?? '';
        $content = json_decode(file_get_contents($path), true);
        if (!empty($type)) {
            $content = $content[$type] ?? [];
        }
        if (!empty($quota)) {
            $content = $content[$quota] ?? [];
        }
        return success(message($content));
    }

    /**
     * 模拟成功
     * @return Response
     */
    public function submit(): Response
    {
        return success(message());
    }

}